//
//  SEGElevatorControlCell.m
//  SEGIntelligentHardware
//
//  Created by 乔杨 on 2020/5/7.
//

#import "SEGElevatorControlCell.h"

@interface SEGElevatorControlCell ()

/// icon
@property (nonatomic, strong) UIImageView *iconImgV;
/// name
@property (nonatomic, strong) UILabel *nameLab;

@end

@implementation SEGElevatorControlCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kColor_W;
        [self createUI];
    }
    return self;
}
- (void)createUI {
    [self addSubview:self.iconImgV];
    [self addSubview:self.nameLab];
    self.nameLab.numberOfLines = 2;
    self.nameLab.preferredMaxLayoutWidth = self.width-30;
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImgV.mas_bottom).mas_offset(8);
        make.left.equalTo(self).mas_offset(15);
        make.right.equalTo(self).mas_offset(-15);
    }];
}
- (void)refreshCellWithModel:(SEGElevGroupListModel *)model {
    if ([model.elevType isEqualToString:@"0"]) { // 蓝牙
        self.iconImgV.image = [UIImage imageWithContentsOfFile:SEGPicName(@"icon_bluetooth_lift")];
    } else { // 二维码
        self.iconImgV.image = [UIImage imageWithContentsOfFile:SEGPicName(@"icon_qrcode_lift")];
    }
    self.nameLab.text = model.elevName ?: @"";
}

#pragma mark - Getter
- (UIImageView *)iconImgV {
    if (!_iconImgV) {
        CGRect rect = CGRectMake((self.width-60)/2, 0, 60, 60);
        _iconImgV = [[UIImageView alloc] initWithFrame:rect];
        _iconImgV.backgroundColor = self.backgroundColor;
        _iconImgV.backgroundColor = kColor_W;
    }
    return _iconImgV;
}
- (UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.backgroundColor = self.backgroundColor;
        _nameLab.textColor = kColor_1;
        _nameLab.font = kFont_13;
        _nameLab.layer.masksToBounds = YES;
        _nameLab.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLab;
}

@end
